{{- $collapsed := default false .Site.Params.sidebar.collapsed }}
{{- with $.Site.Params.repo -}}
{{- $url := .url -}}
{{- $sourceUrlFormat := "%s/blob/%s" }}
{{- $editUrlFormat := "%s/edit/%s" }}
{{- $commitUrlFormat := "%s/commit/%s" }}
{{- if findRE "gitlab.com" $url }}
    {{- $sourceUrlFormat = "%s/-/blob/%s" }}
    {{- $editUrlFormat = "%s/-/edit/%s" }}
    {{- $commitUrlFormat = "%s/-/commit/%s" }}
{{- end }}
{{- $branch := default "master" .branch -}}
{{- $dateFormat := default "02/01/2006, 15:04:05 PM" .dateFormat -}}
{{- $subPath := default "" .subPath -}}
{{- $root := partialCached "functions/working-directory" . }}
{{- if $subPath -}}{{ $subPath = printf "/%s" $subPath }}{{- end -}}
<div class="accordion">
    <div class="accordion-item docs-repo row card component">
        <div class="card-header accordion-header" id="repo-header">
            <h2 class="card-title fs-4 my-2 text-surface d-none d-lg-block">{{ i18n "repo_title" }}</h2>
            <a
                class="accordion-button d-lg-none mb-1 shadow-none p-0 bg-transparent{{ if $collapsed }} collapsed{{ end }}"
                role="button" data-bs-toggle="collapse" href="#repo" aria-expanded="{{ if $collapsed }}false{{ else }}true{{ end }}" aria-controls="repo">
                {{ i18n "repo_title" }}
            </a>
        </div>
        <div class="card-body collapse accordion-collapse accordion-body text-secondary-on-surface d-lg-block{{ if not $collapsed }} show{{ end }}" id="repo" aria-labelledby="repo-header">
            <ul class="list-unstyled">
                {{- if $.File -}}
                {{- $filePath := printf "%s/%s%s" $branch $subPath (strings.TrimPrefix $root $.File.Filename) -}}
                <li class="mb-1">
                    <a href="{{ printf $sourceUrlFormat $url $filePath }}" target="_blank" rel="noopener noreferrer">
                        <i class="fas fa-fw fa-file-archive text-success"></i> {{ i18n "repo_action_view" }}
                    </a>
                </li>
                <li class="mb-1">
                    <a href="{{ printf $editUrlFormat $url $filePath  }}" target="_blank" rel="noopener noreferrer">
                        <i class="fas fa-fw fa-edit text-primary"></i> {{ i18n "repo_action_edit" }}
                    </a>
                </li>
                {{- end -}}
                {{- with $.GitInfo -}}
                <li class="mb-1">
                    <i class="fas fa-fw fa-code text-warning"></i> <a href="{{ printf $commitUrlFormat $url .Hash }}" target="_blank" rel="noopener noreferrer">{{ .AbbreviatedHash }}</a>
                </li>
                <li class="mb-1">
                    <i class="fas fa-fw fa-history text-info"></i> {{ .AuthorDate.Format $dateFormat }}
                </li>
                {{- end -}}
            </ul>
        </div>
    </div>
</div>
{{- end -}}
